package com.xmy.cultivate.mapper;

import com.xmy.cultivate.entity.OrderDetail;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;

/**
 * <p>
 * 订单报名信息 Mapper 接口
 * </p>
 *
 * @author hpiggy
 * @since 2023-08-17
 */
public interface OrderDetailMapper extends BaseMapper<OrderDetail> {

    /**
     * 获取科目的剩余金额
     * @param schoolId
     * @param studentId
     * @param subjectsId
     * @param yearAndQuarter
     * @return
     */
    @Select({"<script>",
            "select IFNULL(sum(a.residue_price),0) as residue_rice  from order_detail as a",
            "where 1=1",
            "<when test='schoolId!=null and schoolId!=&apos;&apos; '>",
            "a.school_id= #{schoolId}",
            "</when>",
            "and a.student_id = #{studentId} and a.subjects_id = #{subjectsId} and a.status &lt;&gt;2 and a.year_and_quarter &gt;= #{yearAndQuarter} and a.deleted = 0 ",
            "</script>"})
    public abstract BigDecimal getAllResiduePrice(@Param("schoolId") Long schoolId, @Param("studentId") Long studentId, @Param("subjectsId") Long subjectsId, @Param("yearAndQuarter") Integer yearAndQuarter);


    /**
     * 获取科目的剩余金额
     * @param schoolId
     * @param studentId
     * @param subjectsId
     * @param yearAndQuarter
     * @return
     */
    @Select({"<script>",
            "select IFNULL(sum(a.residue_course_count),0) as residue_course_count  from order_detail as a",
            "where 1=1",
            "and lesson_type = ${lessonType}",
            "<when test='schoolId!=null and schoolId!=&apos;&apos; '>",
            "a.school_id= #{schoolId}",
            "</when>",
            "and a.student_id = #{studentId} and a.subjects_id = #{subjectsId} and a.status &lt;&gt;2 and a.year_and_quarter &gt;= #{yearAndQuarter} and a.deleted = 0 ",
            "</script>"})
    public abstract Integer getAllResidueHouse(@Param("schoolId") Long schoolId, @Param("studentId") Long studentId, @Param("subjectsId") Long subjectsId, @Param("yearAndQuarter") Integer yearAndQuarter,@Param("lessonType") Integer lessonType);

}
